package common.Tables;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * class Psychologists.
 * represents the Psychologists table
 * @author michal
 *
 */
public class Psychologists implements Serializable,Table{	
	private static final long serialVersionUID = 1L;
	private String  id;	//psychologist's id
	private String firstName;	//psych's name
	private float weightPerDay;	//weight per day allowed for psych
	private Set<PsychTasksWeights> psychTasksWeights;	//set of PsychTasksWeights
	private Set<Availability> availability = new HashSet<Availability>(0);	//set of Availability
	private Set<Arrangement> arrangements = new HashSet<Arrangement>(0);	//set of Arrangement
	private String isActive;	//isActive field
	private Set<TasksNotes> tasksNotes = new  HashSet<TasksNotes>(0);	//set of TasksNotes

	/*
	 * getters & setters
	 */
	public Set<TasksNotes> getTasksNotes() {
		return tasksNotes;
	}
	public void setTasksNotes(Set<TasksNotes> tasksNotes) {
		this.tasksNotes = tasksNotes;
	}
	public String getIsActive() {
		return isActive;
	}
	public void setIsActive(String isActive) {
		this.isActive = isActive;
	}
	public float getWeightPerDay() {
		return weightPerDay;
	}
	public void setWeightPerDay(float weightPerDay) {
		this.weightPerDay = weightPerDay;
	}
	public void addTaskWeight(PsychTasksWeights psychTasksWeights){
		this.psychTasksWeights.add(psychTasksWeights);
	}
	public Set<PsychTasksWeights> getPsychTasksWeights() {
		return psychTasksWeights;
	}
	public void setPsychTasksWeights(Set<PsychTasksWeights> psychTasksWeights) {
		this.psychTasksWeights = psychTasksWeights;
	}	
	public Set<Availability> getAvailability() {
		return availability;
	}
	public void setAvailability(Set<Availability> availability) {
		this.availability = availability;
	}
	public void addAvailability(Availability avl){
		this.availability.add(avl);
	}	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public void setArrangements(Set<Arrangement> arrangements) {
		this.arrangements = arrangements;
	}
	public Set<Arrangement> getArrangements() {
		return arrangements;
	}
	/**
	 * c-tor using fields
	 * @param firstName
	 * @param lastName
	 */
	public Psychologists(String firstName,String id,String isActive){
		this.firstName=firstName;
		this.id=id;
		weightPerDay = 0;	//default is 0
		this.isActive=isActive;		
	}
	/**
	 * default c-tor
	 */
	public Psychologists(){
		weightPerDay = 0;		
	}
	//toString override
	public String toString(){
		return "ID: "+id+" FirstName: "+firstName;
	}

	/**
	 * return true if the other object is the same Psychologists
	 */
	@Override
	public boolean equals(Object obj) {
		if(obj == this){ 
			return true;          
		}          
		if(obj == null || obj.getClass() != this.getClass()){
			return false;        
		}                  
		Psychologists psyc = (Psychologists) obj;             
		return id == psyc.getId() ;                    
	}
	
	/**
	 * method gets a Task object and removes the TaskNotes object that is
	 * connected to it
	 * @param task
	 */
	public void removeTask(Tasks task){
		for (TasksNotes tpp : tasksNotes){
			if (tpp.getTaskID().equals(task)){
				tasksNotes.remove(tpp);				
				break;
			}
		}
	}

	/**
	 * return true if the other object is the same Psychologists
	 */
	public boolean equals(Psychologists p){
		if (p==null)
			return false;
		else if (this.id.trim().equals(p.id.trim()))
			return true;
		else return false;
	}
	/**
	 * method gets a date and returns the psych's currentWeight for this day
	 * @param date
	 * @return
	 */
	public float getCurrentWeightPerDate(String date) {
		float ans = 0;
		Iterator<PsychTasksWeights> it = psychTasksWeights.iterator();
		PsychTasksWeights ptw;
		while (it.hasNext()){	//iterating the PsychTasksWeights set
			ptw = it.next();
			if (ptw.getDate().trim().equals(date)){	//matches the date given
				ans= ptw.getCurrentWeight();
				break;
			}
		}
		return ans;	//if not exist in table than the psychologist's weight is 0. 
	}
	/**
	 * gets a TasksNotes object and adds it to the tasksNotes set.
	 * @param tn
	 */
	public void addTaskNote(TasksNotes tn) {
		tasksNotes.add(tn);
	}
	
	
}
